﻿@{
}

<div class="weui-tab__panel" id="container">
    <div class="page home js_show">
        <div class="page__bd page__bd_spacing">
            <br />
            <ul role="menubar" aria-label="">
                <li role="none" class="">
                    <div class="weui-flex js_category" code="a" aria-haspopup="true" aria-expanded="false" tabindex="0" wah-hotarea="click" aria-live="assertive">
                        <p class="weui-flex__item">前锥：<strong id="spec06"></strong></p>
                        <span role="button"><strong id="devliver06" style="color:red;"></strong>/<strong id="count06"></strong></span>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">前锥：</div>
                            <div class="weui-cell__bd">
                                <p>a1</p>
                            </div>
                            <div id="btns_a1" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">前锥：</div>
                            <div class="weui-cell__bd">
                                <p>a2</p>
                            </div>
                            <div id="btns_a2" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">前锥：</div>
                            <div class="weui-cell__bd">
                                <p>a3</p>
                            </div>
                            <div id="btns_a3" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">前锥：</div>
                            <div class="weui-cell__bd">
                                <p>a4</p>
                            </div>
                            <div id="btns_a4" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                </li>

                <li role="none" class="">
                    <div class="weui-flex js_category" code="b" aria-haspopup="true" aria-expanded="false" tabindex="0" wah-hotarea="click" aria-live="assertive">
                        <p class="weui-flex__item">中锥：<strong id="spec08"></strong></p>
                        <span role="button"><strong id="devliver08" style="color:red;"></strong>/<strong id="count08"></strong></span>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">中锥：</div>
                            <div class="weui-cell__bd">
                                <p>b1</p>
                            </div>
                            <div id="btns_b1" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">中锥：</div>
                            <div class="weui-cell__bd">
                                <p>b2</p>
                            </div>
                            <div id="btns_b2" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">中锥：</div>
                            <div class="weui-cell__bd">
                                <p>b3</p>
                            </div>
                            <div id="btns_b3" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">中锥：</div>
                            <div class="weui-cell__bd">
                                <p>b4</p>
                            </div>
                            <div id="btns_b4" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                </li>

                <li role="none" class="">
                    <div class="weui-flex js_category" code="c" aria-haspopup="true" aria-expanded="false" tabindex="0" wah-hotarea="click" aria-live="assertive">
                        <p class="weui-flex__item">后锥：<strong id="spec09"></strong></p>
                        <span role="button"><strong id="devliver09" style="color:red;"></strong>/<strong id="count09"></strong></span>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">后锥：</div>
                            <div class="weui-cell__bd">
                                <p>c1</p>
                            </div>
                            <div id="btns_c1" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">后锥：</div>
                            <div class="weui-cell__bd">
                                <p>c2</p>
                            </div>
                            <div id="btns_c2" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">后锥：</div>
                            <div class="weui-cell__bd">
                                <p>c3</p>
                            </div>
                            <div id="btns_c3" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">后锥：</div>
                            <div class="weui-cell__bd">
                                <p>c4</p>
                            </div>
                            <div id="btns_c4" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                </li>

                <li role="none" class="">
                    <div class="weui-flex js_category" code="d" aria-haspopup="true" aria-expanded="false" tabindex="0" wah-hotarea="click" aria-live="assertive">
                        <p class="weui-flex__item">中筒：<strong id="spec07"></strong></p>
                        <span role="button"><strong id="devliver07" style="color:red;"></strong>/<strong id="count07"></strong></span>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">中筒：</div>
                            <div class="weui-cell__bd">
                                <p>d1</p>
                            </div>
                            <div id="btns_d1" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                </li>

                <li role="none" class="">
                    <div class="weui-flex js_category" code="g" aria-haspopup="true" aria-expanded="false" tabindex="0" wah-hotarea="click" aria-live="assertive">
                        <p class="weui-flex__item">滚道：<strong id="spec15"></strong></p>
                        <span role="button"><strong id="devliver15" style="color:red;"></strong>/<strong id="count15"></strong></span>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">滚道：</div>
                            <div class="weui-cell__bd">
                                <p>g1</p>
                            </div>
                            <div id="btns_g1" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">滚道：</div>
                            <div class="weui-cell__bd">
                                <p>g2</p>
                            </div>
                            <div id="btns_g2" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">滚道：</div>
                            <div class="weui-cell__bd">
                                <p>g3</p>
                            </div>
                            <div id="btns_g3" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">滚道：</div>
                            <div class="weui-cell__bd">
                                <p>g4</p>
                            </div>
                            <div id="btns_g4" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                </li>

                <li role="none" class="">
                    <div class="weui-flex js_category" code="s" aria-haspopup="true" aria-expanded="false" tabindex="0" wah-hotarea="click" aria-live="assertive">
                        <p class="weui-flex__item">封头：<strong id="spec10"></strong></p>
                        <span role="button"><strong id="devliver10" style="color:red;"></strong>/<strong id="count10"></strong></span>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">封头：</div>
                            <div class="weui-cell__bd">
                                <p>s1</p>
                            </div>
                            <div id="btns_s1" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                    <div class="page__category js_categoryInner" role="menu" aria-hidden="true" data-height="280" style="">
                        <div role="option" class="weui-cell  weui-cell_example">
                            <div class="weui-cell__hd">封头：</div>
                            <div class="weui-cell__bd">
                                <p>s2</p>
                            </div>
                            <div id="btns_s2" class="weui-cell_select-after">
                            </div>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
    </div>
    <script type="text/template" id="ttplan">
        <div role="option" class="weui-form-preview__hd">
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">{{name}}</label>
                <em class="weui-form-preview__value"><strong style="color:red;">{{count}}</strong>个</em>
            </div>
        </div>
        <div role="option" aria-labelledby="p1 js_a11y_comma p2 js_a11y_comma p3" class="weui-form-preview__bd">
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">产品编码</label>
                <span class="weui-form-preview__value">{{code}}</span>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">计划日期</label>
                <span class="weui-form-preview__value">{{planDate}}</span>
            </div>
        </div>
    </script>
    <script type="text/template" id="locBtn_status_0">
        <a href="javascript:ModifyLocStatus('{{locCode}}', '1', '{{eleCode}}');" class="weui-btn weui-btn_mini weui-btn_disabled weui-btn_default">配盘</a>
        <a href="javascript:ModifyLocStatus('{{locCode}}', '2', '{{eleCode}}');" class="weui-btn weui-btn_mini weui-btn_disabled weui-btn_default">送料</a>
        <a href="javascript:void(0);" class="weui-btn weui-btn_mini weui-btn_primary">要框</a>
    </script>
    <script type="text/template" id="locBtn_status_1">
        <a href="javascript:void(0);" class="weui-btn weui-btn_mini weui-btn_primary">配盘</a>
        <a href="javascript:ModifyLocStatus('{{locCode}}', '2', '{{eleCode}}');" class="weui-btn weui-btn_mini weui-btn_disabled weui-btn_default">送料</a>
        <a href="javascript:ModifyLocStatus('{{locCode}}', '0', '{{eleCode}}');" class="weui-btn weui-btn_mini weui-btn_disabled weui-btn_default">要框</a>
    </script>
    <script type="text/template" id="locBtn_status_2">
        <a href="javascript:ModifyLocStatus('{{locCode}}', '1', '{{eleCode}}');" class="weui-btn weui-btn_mini weui-btn_disabled weui-btn_default">配盘</a>
        <a href="javascript:void(0);" class="weui-btn weui-btn_mini weui-btn_primary">送料</a>
        <a href="javascript:ModifyLocStatus('{{locCode}}', '0', '{{eleCode}}');" class="weui-btn weui-btn_mini weui-btn_disabled weui-btn_default">要框</a>
    </script>
    <script type="text/javascript">
        var _url = "http://192.168.98.127:8020/CtrPms";
        var _productEleCode = "1";
        var _curCode = "a";
        var _locStatus = { a1: "-1", a2: "-1", a3: "-1", a4: "-1", b1: "-1", b2: "-1", b3: "-1", b4: "-1", c1: "-1", c2: "-1", c3: "-1", c4: "-1", d1: "-1", g1: "-1", g2: "-1", g3: "-1", g4: "-1", s1: "-1", s2: "-1" };

        $(function () {
            LoadPlanData();
            LoadLocationStatus();
            //隐藏导航
            $(".weui-tabbar").hide();
        });
        function LoadPlanData() {
            $.ajax({
                url: _url + "/CurrentPlan"
                , success: function (nid) {
                    if (nid == "" || nid == null || nid == undefined) {
                        window.location.href = "@Url.Action("Privacy")";
                    }
                    else {
                        $.ajax({
                            url: _url + "/DeliveryState?planId=" + nid
                            , success: function (data) {
                                _productEleCode = data.eleCode;
                                var itemStr = $("#ttplan").html();
                                itemStr = itemStr.replace("{{name}}", data.name);
                                itemStr = itemStr.replace("{{code}}", data.code);
                                itemStr = itemStr.replace("{{count}}", data.count);
                                itemStr = itemStr.replace("{{quantity}}", data.quantity);
                                itemStr = itemStr.replace("{{planDate}}", data.planDate);

                                $("#plan_container").html(itemStr);

                                $(data.prepares).each(function () {
                                    var item = this;
                                    $("#spec" + item.eleCode).html(item.specName);
                                    $("#devliver" + item.eleCode).html(item.deliveryCount);
                                    $("#count" + item.eleCode).html(item.count);
                                });
                            }
                        });
                    }
                }
            });
        }

        function LoadLocationStatus() {
            $.ajax({
                url: _url + "/LocationStatus?code=" + _curCode
                , success: function (data) {
                    if (_curCode == "a") {
                        CheckLocationStatus_A(data, "06");
                    } else if (_curCode == "b") {
                        CheckLocationStatus_B(data, "06");
                    } else if (_curCode == "c") {
                        CheckLocationStatus_C(data, "09");
                    } else if (_curCode == "d") {
                        CheckLocationStatus_D(data, "07");
                    } else if (_curCode == "g") {
                        CheckLocationStatus_G(data, "15");
                    } else if (_curCode == "s") {
                        CheckLocationStatus_S(data, "10");
                    }
                }
            });

            setTimeout(function () {
                LoadLocationStatus();
            }, 1000 * 10);
        }

        function CheckLocationStatus_A(data, eleType) {
            if (data.a1 != _locStatus.a1) {
                _locStatus.a1 = data.a1;
                ReSetLocationBtns("a1", data.a1, eleType);
            }

            if (data.a2 != _locStatus.a2) {
                _locStatus.a2 = data.a2;
                ReSetLocationBtns("a2", data.a2, eleType);
            }

            if (data.a3 != _locStatus.a3) {
                _locStatus.a3 = data.a3;
                ReSetLocationBtns("a3", data.a3, eleType);
            }

            if (data.a4 != _locStatus.a4) {
                _locStatus.a4 = data.a4;
                ReSetLocationBtns("a4", data.a4, eleType);
            }
        }

        function CheckLocationStatus_B(data, eleType) {
            if (data.b1 != _locStatus.b1) {
                _locStatus.b1 = data.b1;
                ReSetLocationBtns("b1", data.b1, eleType);
            }

            if (data.b2 != _locStatus.b2) {
                _locStatus.b2 = data.b2;
                ReSetLocationBtns("b2", data.b2, eleType);
            }

            if (data.b3 != _locStatus.b3) {
                _locStatus.b3 = data.b3;
                ReSetLocationBtns("b3", data.b3, eleType);
            }

            if (data.b4 != _locStatus.b4) {
                _locStatus.b4 = data.b4;
                ReSetLocationBtns("b4", data.b4, eleType);
            }
        }

        function CheckLocationStatus_C(data, eleType) {
            if (data.c1 != _locStatus.c1) {
                _locStatus.c1 = data.c1;
                ReSetLocationBtns("c1", data.c1, eleType);
            }

            if (data.c2 != _locStatus.c2) {
                _locStatus.c2 = data.c2;
                ReSetLocationBtns("c2", data.c2, eleType);
            }

            if (data.c3 != _locStatus.c3) {
                _locStatus.c3 = data.c3;
                ReSetLocationBtns("c3", data.c3, eleType);
            }

            if (data.c4 != _locStatus.c4) {
                _locStatus.c4 = data.c4;
                ReSetLocationBtns("c4", data.c4, eleType);
            }
        }

        function CheckLocationStatus_D(data, eleType) {
            if (data.d1 != _locStatus.d1) {
                _locStatus.d1 = data.d1;
                ReSetLocationBtns("d1", data.d1, eleType);
            }
        }

        function CheckLocationStatus_G(data, eleType) {
            if (data.g1 != _locStatus.g1) {
                _locStatus.g1 = data.g1;
                ReSetLocationBtns("g1", data.g1, eleType);
            }

            if (data.g2 != _locStatus.g2) {
                _locStatus.g2 = data.g2;
                ReSetLocationBtns("g2", data.g2, eleType);
            }

            if (data.g3 != _locStatus.g3) {
                _locStatus.g3 = data.g3;
                ReSetLocationBtns("g3", data.g3, eleType);
            }

            if (data.g4 != _locStatus.g4) {
                _locStatus.g4 = data.g4;
                ReSetLocationBtns("g4", data.g4, eleType);
            }
        }

        function CheckLocationStatus_S(data, eleType) {
            if (data.s1 != _locStatus.s1) {
                _locStatus.s1 = data.s1;
                ReSetLocationBtns("s1", data.s1, eleType);
            }

            if (data.s2 != _locStatus.s2) {
                _locStatus.s2 = data.s2;
                ReSetLocationBtns("s2", data.s2, eleType);
            }
        }

        function ReSetLocationBtns(code, value, eleType) {
            var tpHtml = $("#locBtn_status_" + value).html();
            tpHtml = tpHtml.replaceAll("{{locCode}}", code);
            tpHtml = tpHtml.replaceAll("{{eleCode}}", eleType);
            $("#btns_" + code).html(tpHtml);
        }

        function ModifyLocStatus(locCode, status, eleCode) {
            if (status == "0") {
                if (confirm("确定【料位" + locCode+"】【无料框】吗？点击【确定】将呼叫AGV送来【空料框】至料位。")) {
                    PostLocStatus(locCode, status, eleCode);
                }
            } else if (status == "1") {
                if (confirm("确定【料位" + locCode + "】仅有【空框】吗？点击【确定】将此料位标识为【配盘中】。")) {
                    PostLocStatus(locCode, status, eleCode);
                }
            } else if (status == "2") {
                if (confirm("确定【料位" + locCode + "】已【配盘完成】吗？点击【确定】将呼叫AGV送走【物料】至生产工位。")) {
                    PostLocStatus(locCode, status, eleCode);
                }
            }
        }

        function PostLocStatus(locCode, status, eleCode) {
            $.ajax({
                url: _url + "/ModifyLocationStatus?locCode=" + locCode + "&status=" + status + "&eleCode=" + _productEleCode + eleCode
                , success: function (data) {
                    LoadLocationStatus();
                }
            });
        }
    </script>
    <script type="text/javascript" class="home js_show">
           $(function () {
               function setFoot() {
                   var $foot = $('.page__ft');
                   if ($foot.length > 0) {
                       $foot.removeClass('j_bottom');
                       var winH = $(window).height();
                       if ($foot.offsetTop + $foot.offsetHeight < winH) {
                           $foot.addClass('j_bottom');
                       }
                   }
               }
               var winH = $(window).height();
               var categorySpace = 10;
               function expandMenu() {
                   setFoot();
                   var $this = $(this),
                       $inner = $this.next('.js_categoryInner'),
                       $page = $this.parents('.page').first(),
                       $parent = $(this).parent('li');
                   var innerH = $inner.data('height');

                   if (!innerH) {
                       $inner.css('height', 'auto');
                       innerH = $inner.height();
                       $inner.removeAttr('style');
                       $inner.data('height', innerH);
                   }

                   if ($parent.hasClass('js_show')) {
                       $parent.removeClass('js_show');
                       $this.attr('aria-expanded', 'false');
                       $this.children('img').attr('alt', ' 展开');
                       $inner.attr('aria-hidden', 'true');
                       //$('.js_item', $(this).siblings()).attr('tabindex', '-1');
                   } else {
                       $parent.siblings().removeClass('js_show');
                       $parent.siblings().children('.js_category').attr('aria-expanded', 'false');
                       $parent.siblings().children('.js_category img').attr('alt', ' 展开');
                       $parent.siblings().children('.js_categoryInner').attr('aria-hidden', 'true');
                       //$('.js_item', $parent.siblings().children('.js_categoryInner')).attr('tabindex', '-1');

                       $parent.addClass('js_show');
                       $this.attr('aria-expanded', 'true');
                       $this.children('img').attr('alt', ' 收起');
                       $inner.attr('aria-hidden', 'false');
                       //$('.js_item', $(this).siblings()).attr('tabindex', '0');

                       if (this.offsetTop + this.offsetHeight + innerH > $page.scrollTop() + winH) {
                           var scrollTop = this.offsetTop + this.offsetHeight + innerH - winH + categorySpace;

                           if (scrollTop > this.offsetTop) {
                               scrollTop = this.offsetTop - categorySpace;
                           }
                           $page.scrollTop(scrollTop);
                       }
                   }

                   var winH = $(window).height();
                   var $foot = $('body').find('.page__ft');
                   if ($foot.length < 1) return;

                   if ($foot.position().top + $foot.height() < winH) {
                       $foot.addClass('j_bottom');
                   } else {
                       $foot.removeClass('j_bottom');
                   }
               }

               $('.js_category').attr('tabindex', '0');
               $('.js_category').on('click', function () {
                   _curCode = $(this).attr("code");
                   LoadLocationStatus();

                   $(this).attr('aria-live', 'assertive');
                   expandMenu.call(this);
               });
               $('.js_category').on('keydown', function (event) {
                   if (event.keyCode === 13) {
                       expandMenu.call(this);
                   }
               });

          //$("#tab1").attr('aria-selected','true').addClass('weui-bar__item_on');
           });
    </script>
</div>
